﻿using System.Data;
using IntelligentStorWpfApp.Interface;
using IntelligentStorWpfApp.Model;
using MySql.Data.MySqlClient;
using IntelligentStorWpfApp.Helper;

namespace IntelligentStorWpfApp.Services
{
    public class UserServices : UserInterface
    {
        string sqlStr = "";
        public bool AddUser(User user)
        {
            sqlStr = "INSERT INTO c_user ( FaceId, UserName,UserPwd) VALUES ( @FaceId,@UserName,@UserPwd);";
            MySqlParameter[] paras =
            {
                new MySqlParameter("@FaceId",user.FaceId),
                new MySqlParameter ("@UserName",user.UserName),
                new MySqlParameter ("@UserPwd",user.UserPwd)
            };
            return DBHelper.ExecuteNonQuery(sqlStr, paras);

        }
        public DataTable GetUsers(User user)
        {
            sqlStr = "SELECT * from c_user WHERE UserName=@UserName and UserPwd=@UserPwd;";
            MySqlParameter[] paras =
            {
                new MySqlParameter ("@UserName",user.UserName),
                new MySqlParameter ("@UserPwd",user.UserPwd)
            };
            return DBHelper.ExecuteDataSet(sqlStr, paras);

        }

        public DataTable GetAllUsers()
        {
            sqlStr = "SELECT * from c_user;";
            return DBHelper.ExecuteDataSet(sqlStr, null);
        }

        public bool UpdateUserFace(User user)
        {
            sqlStr = "UPDATE c_user SET FaceId = @FaceId WHERE UserName = @UserName;";
            MySqlParameter[] paras =
            {
                new MySqlParameter ("@FaceId",user.FaceId),
                new MySqlParameter ("@UserName",user.UserName)
            };

            return DBHelper.ExecuteNonQuery(sqlStr,paras);
        }
    }
}
